package com.imooc.springcloud.hystrix;

import com.imooc.springcloud.Friend;
import com.imooc.springcloud.MyService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @describte:定义降级逻辑 针对MyService的容错类
 * @program:spring-cloud-demo
 * @author:zhengdp
 * @create:2021-10-02 23:33:59
 **/
@Slf4j
@Component
public class Fallback implements MyService {

    @HystrixCommand(fallbackMethod = "fallback2")
    @Override
    public String error() {
        log.info("Fallback: I'm not a black sheep any more");
        throw new RuntimeException("first fallback");
    }

    @HystrixCommand(fallbackMethod = "fallback3")
    public String fallback2(){
        log.info("fallback again");
        throw new RuntimeException("fallback again");
    }

    public String fallback3(){
        log.info("fallback again and again");
        return "success";
    }

    @Override
    public String retry(int timeout) {
        return "You are late!";
    }

    @Override
    public String sayHi() {
        return null;
    }

    @Override
    public Friend sayHiPost(Friend friend) {
        return null;
    }



}
